<?php

namespace app\admin\model;

use app\common\model\BaseModel;


class Usermoneylog extends BaseModel
{


    // 表名
    protected $name = 'user_money_log';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'oper_type_text'
    ];


    public function getList($where, $size = 12, $field = '*', $order = 'id desc')
    {
        $list = $this->where(function ($query) use ($where) {

            if (isset($where['user_id']) && $where['user_id'] > 0) {
                $query->where('user_id', $where['user_id']);
            }
        })
            ->with([])
            ->field($field)
            ->order($order)
            ->paginate($size);
        //$list->each(function ($item) {
        //});
        return $list->toArray();

    }


    public function getOperTypeList()
    {
        return ['1' => __('Oper_type 1'), '2' => __('Oper_type 2')];
    }


    public function getOperTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['oper_type']) ? $data['oper_type'] : '');
        $list = $this->getOperTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function admin()
    {
        return $this->belongsTo('admin', 'admin_id', 'id');
    }


    public function userinfo()
    {
        return $this->belongsTo('user', 'user_id', 'id');
    }

}
